/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Cubos;

import bin.Venda;
import gui.JanelaPrincipal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Vinicius
 */
public class JanelaBi extends javax.swing.JInternalFrame {

    private JanelaPrincipal janelaPrincipal;
    
    /**
     * Creates new form JanelaBi
     */
    public JanelaBi(JanelaPrincipal janelaPrincipal) {
        this.janelaPrincipal = janelaPrincipal;
        
        initComponents();
        
        this.txtArea.setContentType("text/html");
        this.imprimirResultados();
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GrupoBotoes = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtArea = new javax.swing.JEditorPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setTitle("Cubo Faturamento");

        txtArea.setEditable(false);
        jScrollPane1.setViewportView(txtArea);

        jMenu1.setText("Fechar");
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu1MouseClicked(evt);
            }
        });
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Opções");

        jMenuItem1.setText("Atualizar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 784, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        this.imprimirResultados();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
        this.janelaPrincipal.getJanelaFactory().liberarJanela("[Menu, Cubos, Cubo Faturamento]");
        this.dispose();
    }//GEN-LAST:event_jMenu1MouseClicked

    public void imprimirResultados()
    {
        String resultado = "Data de hoje: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date()) + "<br><table border=1 width=100%><tr bgcolor=#FFA54F><td>Ano</td><td>Mês</td><td>Dia</td><td>Cliente</td><td>Valor da Venda</td></tr>";
        
        List<String[]> listaResultados = new ArrayList<String[]>();
        for(Venda v : this.janelaPrincipal.getArmazem().getListaVendas())
        {
            listaResultados.add(new String[]{new SimpleDateFormat("YYYY").format(v.getDataVenda()),new SimpleDateFormat("MM").format(v.getDataVenda()),
            new SimpleDateFormat("d").format(v.getDataVenda()),v.getCliente().getId() + " - " + v.getCliente().getNome(), v.getValorTotal() + ""});
        }
        
        for(String[] str : listaResultados)
        {
            resultado += "<tr bgcolor=#98FB98 align=center><td>"+str[0]+"</td><td>"+str[1]+"</td><td>"+str[2]+"</td><td>"+str[3]+"</td><td bgcolor=#40E0D0>"+str[4]+"</td></tr>";
        }
        this.txtArea.setText(resultado += "</table>");
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GrupoBotoes;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JEditorPane txtArea;
    // End of variables declaration//GEN-END:variables
}
